﻿Imports NHibernate.Event.Default
Public Class SoftDeleteListener
    Inherits DefaultDeleteEventListener
    Protected Overrides Sub DeleteEntity(ByVal session As NHibernate.Event.IEventSource, ByVal entity As Object, ByVal entityEntry As NHibernate.Engine.EntityEntry, ByVal isCascadeDeleteEnabled As Boolean, ByVal persister As NHibernate.Persister.Entity.IEntityPersister, ByVal transientEntities As Iesi.Collections.ISet)
        If (TypeOf entity Is IPermanentRecord) Then

            DirectCast(entity, IPermanentRecord).deleted = True
            me.CascadeBeforeDelete(session, persister, entity, 
                entityEntry, transientEntities)
            Me.CascadeAfterDelete(session, persister, entity, transientEntities)

        Else

            MyBase.DeleteEntity(session, entity, entityEntry,
                isCascadeDeleteEnabled, persister, transientEntities)
        End If
    End Sub


End Class
